package com.koron.sinoprobe.web.ledger.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.common.core.business.readrecord.ReadRecord;
import com.koron.common.core.interceptor.OrderByInterceptor;
import com.koron.sinoprobe.web.ledger.bean.entity.SpMemorabilia;
import com.koron.sinoprobe.web.ledger.bean.query.SpMemorabiliaQuery;
import com.koron.sinoprobe.web.ledger.bean.vo.SpMemorabiliaVO;
import com.koron.sinoprobe.web.ledger.service.SpMemorabiliaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author twcao
 * @title: SpMemorabiliaController
 * @projectName GDH_EAM_V2
 * @description: 专项项目-大事记
 * @date 2021/12/1320:09
 */
@Slf4j
@RestController
@RequestMapping("/sp/project/memorabilia/")
@Api(tags = "专项台账-项目大事记")
public class SpMemorabiliaController {

    @Autowired
    private SpMemorabiliaService memorabiliaService;

    @ReadRecord(insert = true, skip = true)
    @GetMapping("/selectOne")
    @ApiOperation("项目大事记详情查询")
    @ApiImplicitParam(name = "id", value = "项目大事记id", required = true)
    public Response<SpMemorabilia> selectOne(@CasUser @ApiIgnore EamUser user, @RequestParam @ReadRecord String id) {
        SpMemorabilia detail = ADOConnection.runTask(user.getCurrDs(), memorabiliaService, "queryById", SpMemorabilia.class, id);
        return Response.ok("查询成功", detail);
    }

    @ReadRecord(echo = true)
    @GetMapping("/queryList")
    @ApiOperation("项目大事记分页查询")
    public Response<PageInfo<SpMemorabiliaVO>> queryList(@CasUser @ApiIgnore EamUser user, SpMemorabiliaQuery query) {
        OrderByInterceptor.setOrderBy(query.getOrders());
        PageHelper.startPage(query.getPage(), query.getPageSize());
        List<SpMemorabiliaVO> list = ADOConnection.runTask(user.getCurrDs(), memorabiliaService, "queryList", List.class, query);
        return Response.ok("查询成功", new PageInfo<>(list));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增或修改项目大事记")
    public Response<SpMemorabilia> saveOrUpdate(@CasUser @ApiIgnore EamUser user, @RequestBody SpMemorabilia detail) {
        detail = ADOConnection.runTask(user.getCurrDs(), memorabiliaService, "saveOrUpdate", SpMemorabilia.class, detail);
        return Response.ok("操作成功", detail);
    }

    @GetMapping("/deleteById")
    @ApiOperation("根据id删除项目大事记")
    @ApiImplicitParam(name = "id", value = "项目大事记id", required = true)
    public Response<String> deleteById(@CasUser @ApiIgnore EamUser user, @RequestParam String id) {
        ADOConnection.runTask(user.getCurrDs(), memorabiliaService, "deleteById", Boolean.class, id);
        return Response.ok("删除成功", id);
    }
}
